<template>
  <div>
    <!-- 主体部分 -->
    <section class="main">
      <input
        v-model="isALL"
        id="toggle-all"
        class="toggle-all"
        type="checkbox"
      />
      <label for="toggle-all">Mark all as complete</label>
      <ul class="todo-list">
        
        <!-- 当任务已完成，可以给 li 加上 completed 类，会让元素加上删除线 -->
        <li
          v-for="item in list"
          :key="item.id"
          :class="{ completed: item.flag }"
        >
          <div class="view">
            <input
              class="toggle"
              type="checkbox"
              :checked="item.flag"
              @change="changeFlag($event, item.id)"
            />
            <label>{{ item.value }}</label>
            <button @click="delList(item.id)" class="destroy"></button>
          </div>
        </li>
      </ul>
    </section>
  </div>
</template>

<script>

export default {
  components: {},
  props: {
    list: Array,
  },
  data() {
    return {}
  },
  computed: {
    //全选
    isALL: {
      get() {
        return this.list.every((item) => item.flag)
      },
      set(val) {
        this.$emit('isALL', val)
      },
      
    },
  },
  methods: {
    //删除
    delList(id) {
      this.$emit('delList', id)
    },
    //改变选择状态
    changeFlag(e, id) {
      this.$emit('changeFlag', e.target.checked, id)
    },
  },
}
</script>

<style scoped></style>
